package com.gzc.just.play.last.war.sceneserver.repository;

import com.gzc.just.play.last.war.sceneserver.entity.PlayerAttribute;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * 玩家属性数据访问接口
 */
@Repository
public interface PlayerAttributeRepository extends JpaRepository<PlayerAttribute, Long> {
    
    /**
     * 根据玩家ID和属性类型查找
     */
    @Query("SELECT pa FROM PlayerAttribute pa WHERE pa.player.playerId = :playerId AND pa.attributeType = :attributeType")
    Optional<PlayerAttribute> findByPlayerIdAndAttributeType(@Param("playerId") Long playerId, @Param("attributeType") Integer attributeType);
    
    /**
     * 查找玩家的所有属性
     */
    @Query("SELECT pa FROM PlayerAttribute pa WHERE pa.player.playerId = :playerId")
    List<PlayerAttribute> findByPlayerId(@Param("playerId") Long playerId);
    
    /**
     * 查找指定类型的属性
     */
    List<PlayerAttribute> findByAttributeType(Integer attributeType);
    
    /**
     * 自定义查询：获取玩家的属性总览
     */
    @Query("SELECT pa FROM PlayerAttribute pa WHERE pa.player.playerId = :playerId ORDER BY pa.attributeType")
    List<PlayerAttribute> findPlayerAttributesOverview(@Param("playerId") Long playerId);
    
    /**
     * 分页查询玩家属性
     */
    @Query("SELECT pa FROM PlayerAttribute pa WHERE pa.player.playerId = :playerId")
    Page<PlayerAttribute> findByPlayerId(@Param("playerId") Long playerId, Pageable pageable);
}